import { Controller, Get, Post, Body, Patch, Param, Delete, Request } from '@nestjs/common';
import { ApiOperation, ApiParam, ApiBearerAuth, ApiTags, ApiOkResponse } from '@nestjs/swagger';

import { UserService } from './user.service';
import { UserDto, UserUpdateDto } from './dto/user.dto';
import { LoginDto } from './dto/login.dto';
import { JwtNoVerify } from '../../decorators';

@ApiTags('用户模块')
@Controller('user')
export class UserController {
  constructor(private readonly _userService: UserService) {}

  // 登录
  @Post('login')
  @JwtNoVerify()
  @ApiOperation({ summary: '登录' })
  login(@Body() body: LoginDto) {
    return this._userService.login(body);
  }

  @Get('user-list')
  @JwtNoVerify()
  @ApiOperation({ summary: '获取用户列表' })
  async getUserList(@Request() req) {
    return this._userService.getUserList(req);
  }

  @Post('add-user')
  @ApiBearerAuth()
  @ApiOperation({ summary: '新增用户' })
  async addUser(@Request() req, @Body() UserDto: UserDto) {
    return this._userService.addUser(req, UserDto);
  }

  @Post('update-user')
  @ApiBearerAuth()
  @ApiOperation({ summary: '更新用户' })
  async updateUser(@Request() req, @Body() UserUpdateDto: UserUpdateDto) {
    return this._userService.updateUser(req, UserUpdateDto);
  }

  @Post('delete-user')
  @ApiBearerAuth()
  @ApiOperation({ summary: '删除用户' })
  async deleteUser(@Request() req, @Body() body: any) {
    return this._userService.deleteUser(req, body);
  }
}
